package com.rongke.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.rongke.mapper.CapitalDetailedMapper;
import com.rongke.mapper.UserAccountMapper;
import com.rongke.model.CapitalDetailed;
import com.rongke.model.UserAccount;
import com.rongke.service.UserAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @UserAccountServiceImpl
 * @ServiceImpl
 * @version : Ver 1.0
 */
@Service
@Transactional
public class UserAccountServiceImpl extends ServiceImpl<UserAccountMapper, UserAccount> implements UserAccountService {
    @Autowired
    UserAccountMapper userAccountMapper;
    @Autowired
    CapitalDetailedMapper capitalDetailedMapper;
    @Override
    public boolean charge(UserAccount userAccount, CapitalDetailed capitalDetailed) {
        Integer insert = capitalDetailedMapper.insert(capitalDetailed);
        EntityWrapper<UserAccount> userAccountEntityWrapper = new EntityWrapper<>();
        userAccountEntityWrapper.eq("user_id",userAccount.getUserId());
        Integer update = userAccountMapper.update(userAccount, userAccountEntityWrapper);

        if (insert+update==2){
            return true;
        }
        return false;
    }
}
